// 使用函数式指令，数字过滤
export function useCustomNumber() {
	const handleInput = (event) => {
		const value = event.target.value;
		event.target.value = value.replace(/\D/g, "");
		// event.target.dispatchEvent(new Event("input"));
	};

	return {
		mounted(el, bingding) {
			console.log("bingding=>   ", bingding);
			el.addEventListener("input", handleInput);
		},
		beforeUnmount(el) {
			el.removeEventListener("input", handleInput);
		},
	};
}

async function useDirective(app) {
	await app.directive("custom-number", useCustomNumber());
}

// 注册全局指令
export default useDirective;
